package com.hs.srm.admin.modules.inforecord.controller;

import com.hs.srm.admin.modules.inforecord.entity.PointPriceEntity;
import com.hs.srm.admin.modules.inforecord.service.PointPriceService;
import com.hs.srm.admin.modules.sys.controller.AbstractController;
import com.hs.srm.base.common.annotation.SysLog;
import com.hs.srm.common.utils.PageUtils;
import com.hs.srm.common.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.Date;
import java.util.Map;

/**
 * @author xwx
 * @since 2020-06-04 09:15:11
 */
@RestController
@RequestMapping("/pointPrice")
public class PointPriceController extends AbstractController {

    @Autowired
    private PointPriceService pointPriceService;

    /**
     * 查询列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils pu = this.pointPriceService.queryPage(params);
        return R.ok(pu);
    }

    /**
     * 点价信息保存
     *
     * @param pointPriceEntity
     * @return
     */
    @SysLog("新增点价物料")
    @RequestMapping("/save")
    public R save(PointPriceEntity pointPriceEntity) {
        pointPriceEntity.setCreateDate(new Date());
        pointPriceEntity.setCreateBy(this.getUser().getUsername());
        pointPriceService.insert(pointPriceEntity);
        return R.ok();
    }

    /**
     * 根据物料号判断是否为点价物料
     *
     * @param materialCode
     * @return
     */
    @RequestMapping("/checkMaterialType")
    public R checkMaterialType(@RequestParam(value = "materialCode") String materialCode) {
        boolean result = pointPriceService.checkMaterialType(materialCode);
        return R.ok(result);
    }

    /**
     * 删除点价物料
     *
     * @param pkIds
     * @param materialCode
     * @return
     */
    @SysLog("删除点价物料")
    @RequestMapping("/deletePrice")
    public R deletePrice(@RequestParam(value = "materialCode") String[] materialCode, @RequestParam(value = "pkIds") String[] pkIds) {
        boolean msg = this.pointPriceService.deleteBatchIds(Arrays.asList(pkIds));
        if (msg) {
            return R.ok();
        }
        return R.error();
    }
}